<template>
  <view>
    <loading :showLoaded.sync="showLoaded"></loading>
    <!-- <navBar v-if="isShowCustomNavBar" :navbarData.sync="navbarData"></navBar> -->
    <custom-nav-bar :nav-bar-info="navBarInfo" />
    <tabBar v-if="customTabbar === 1 && tabbarTimeout" :nowPages.sync="nowPages"></tabBar>
    <view :style="{paddingBottom: (isIpx ? 75 : 55) + 'px' }">
      <view v-if="utoolsData" style="position: fixed;">
        <utools-parse id="utools-parse" page="category" @triggerComponent="onTriggerComponent"
          :utools-data="utoolsData"></utools-parse>
      </view>
    </view>
  </view>
</template>

<script>
  import api from '@/api/api';
  import tip from '@/utils/tip';
  import util from '@/utils/util.js'
  import loading from '@/components/common/loading';
  // import itemsSlideslipNew from './itemsSlideslipNew.vue';
  // import itemsTileNew from './itemsTileNew.vue';
  import TabBar from '@/components/common/tabbar';
  import NavBar from '@/components/common/navbar';
  // import FloorNav from './components/floorNav';
  // import registerWidget from "@/components/register/register-widget.vue";
  // import CartToast from '@/components/cartToast.vue';
  import {
    SYSTEM_INFO,
    MERCHANT_INFO,
    CUSTOMER_INFO,
    USER_INFO,
    CART_KEY
  } from '@/utils/constant';
  import {
    reportEvent,
    getEventIdByNavName,
    EVENT_ID
  } from '@/utils/ab-test.js';

  export default {
    components: {
      // itemsSlideslipNew: itemsSlideslipNew,
      // itemsTileNew: itemsTileNew,
      loading: loading,
      tabBar: TabBar,
      // navBar: NavBar,
    },
    data() {
      return {
        tabbarTimeout: false,
        customTabbar: -1,
        nowPages: '',
        isShowCustomNavBar: true,
        // 组件所需的参数
        navbarData: {
          showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
          title: '商城', //导航栏 中间的标题
          newLogo: uni.getStorageInfoSync('storeLogo'),
          isTopFixed: false
        },
        navBarInfo: {
          page: "explpration",
          logo: "https://100000063-1252208446.file.myqcloud.com/images/macallan-remvp/white-logo.png",
          leftIcon: "https://100000063-1252208446.file.myqcloud.com/images/macallan-remvp/search.png",
          backgroundColor: 'transparent',
        },
        storeProductList: [],
        rootcateList: [],
        afterPage: '',
        contentLsitObj: {},
        showLoaded: true,
        preview: false,
        isIpx: true,
        utoolsData: null,
        query: wx.createSelectorQuery(),
        shareImage: '',   //页面分享图片
        shareTitle: '',   //页面分享标题
        pagePath: '',     //页面分享路径
        pageQuery: '',    //页面分享参数
      }
    },
    async onLoad(option = {}) {
      await this.$onLaunched;
      let that = this
      let pages = getCurrentPages();
      var currPage = pages[pages.length - 1];
      this.nowPages = currPage.route;
      this.isIpx = getApp().globalData.isIpx;
      that.customTabbar = this.$programSetting.customTabbar ? 1 : 0
      this.preview = getApp().globalData.cmsPreview ? getApp().globalData.cmsPreview : false;
      this.utid = option.utid
      await this.init(option.utid)
      setTimeout(() => {
        this.showLoaded = false
      }, 600)
      this.getPageShareData();
      // that.showLoaded = false
      // that.rootcateList = res;

      // }).catch((err) => {});
    },
    onUnload() {
      if (this._observer) this._observer.disconnect()
    },
    onShow() {
      let that = this
      // 		getApp().cl_tracker.track('mini_program_view', {
      // 			path: '/pages/explpration/explpration',
      // 			pageName: '探索',
      // 		});

      // 		that.$commonSensors.commonPageView('PLPView')
      setTimeout(() => {
        that.tabbarTimeout = true;
      }, 600)
    },
    onPageScroll(e) {
    },
    //  onReachBottom() {
    //    // 页面触底时执行
    // // this.floorNavData = this.floorNavData.map((item, i) => {
    // // 	item.isSelect = i==this.floorNavData.length-1
    // // 	return item
    // // })
    // // this.floor = this.floorNavData.length-1

    //  },
    methods: {
      async init(id = null) {
        let systemInfo = uni.getSystemInfoSync();
        let rect = uni.getMenuButtonBoundingClientRect ? uni.getMenuButtonBoundingClientRect() :
          null; //胶囊按钮位置信息
        uni.getMenuButtonBoundingClientRect();
        let pixelRatio1 = 750 / wx.getSystemInfoSync().windowWidth;
        let navBarHeight = (function() {
          //导航栏高度
          let gap = rect.top - systemInfo.statusBarHeight; //动态计算每台手机状态栏到胶囊按钮间距
          return 2 * gap + rect.height;
        })();

        // 模板数据
        this.utoolsData = await this.getHomeUtoolsData(id)
        if (this.utoolsData) {
          //商品
          // this.list = await this.getCateGoods(this.utoolsData?.classId ||8066)
          // setTimeout(async() => {
          // this.floorNavData = await this.initloorNavigation()
          // }, 0)
          // // //活动
          // // let list = await  this.drawControl(temporaryProductList)
          // //shangpin曝光买点
          // this.exposeSkuTrack(this.list)
        }
        return null
      },
      async getHomeUtoolsData(id = null) {
        let json;
        if (id) {
          json = await api.getUtoolsJsonP({
            utoolsId: id,
            type: 'exploration'
          });
        } else {
          json = await api.getUtoolsJson({
            type: 'exploration'
          });
        }
        return json.success && json?.data ? JSON.parse(json.data) : null
      },
	  onTriggerComponent(e) {
	    try{
	     this.$commonUtoolsTrack.onTriggerComponent(e);
	    }catch(e){
	      console.log("home-onTriggerComponent-error:", e)
	    }
	  },
      /**
       * 查询分享数据
       * @param {Object} option
       */
      async getPageShareData() {
        try {
          const res = await this.$commonFunction.getShareinfoByCode('exploration');
          this.shareImage = res.shareImage;
          this.shareTitle = res.shareTitle;
          this.pagePath = res.pagePath; //  当前页面路由
          this.pageQuery = res.pageQuery; //  当前页面url参数
        } catch (e) {}
      },
      async onShareAppMessage(res) {
        if (res.from === 'button') {} else {
          this.$EFSTracking.trackingAction('SHARE_CARD', res.from, {});
        }
        let path = '/pages/exploration/exploration';
        this.$commonSensors.sensorsPageShare()
				this.$sr.setContext({ share_title: this.shareTitle || 'THE MACALLAN EBOUTIQUE麦卡伦' });
        return this.$commonFunction.commonShare(res, this.shareTitle, path, this.shareImage)
      },
      onShareTimeline() {
        return {
          title: this.shareTitle,
          query: '',
          imageUrl: this.shareImage
        };
      },

    }
  }
</script>

<style lang="less">
  page {
    background-color: #f6f5f3 !important;
  }


  .doubleMargin {
    margin-top: 105rpx !important;
  }

  .defaultMargin {
    margin-top: 60rpx !important;
  }

  ::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
    color: transparent;
  }
</style>
